import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register')
  },
  {
    path: '/404',
    component: () => import('@/views/404')
  },
  {
    path: '/loading',
    component: () => import('@/views/loading')
  },
  {
    path: '/',
    component: layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: 'Home' }
    }]
  },
  {
    path: '/follow',
    component: layout,
    children: [
      {
        path: '/follow',
        name: 'Follow',
        component: () => import('@/views/follow'),
        meta: { title: 'Follow' }
      }
    ]
  },
  {
    path: '/barCenter',
    component: layout,
    children: [
      {
        path: '/barCenter',
        name: 'BarCenter',
        component: () => import('@/views/barCenter'),
        meta: { title: 'BarCenter' }
      }
    ]
  },
  {
    path: '/secret',
    component: layout,
    children: [
      {
        path: '/secret',
        name: 'Secret',
        component: () => import('@/views/secret'),
        meta: { title: 'Secret' }
      }
    ]
  },
  {
    path: '/message',
    component: layout,
    children: [
      {
        path: '/message',
        name: 'Message',
        component: () => import('@/views/message'),
        meta: { title: 'Message' }
      }
    ]
  },
  {
    path: '/barPage',
    component: layout,
    children: [
      {
        path: '/barPage',
        name: 'BarPage',
        component: () => import('@/views/barPage'),
        meta: { title: 'BarPage' }
      }
    ]
  },
  {
    path: '/userPage',
    component: layout,
    children: [
      {
        path: '/userPage',
        name: 'UserPage',
        // redirect: '/userPage/home',
        component: () => import('@/views/userPage'),
        meta: { title: 'UserPage' },
        children: [
          {
            path: 'home',
            component: () => import('@/views/userPage/home'),
            meta: { title: '主页' }
          },
          {
            path: 'dynamic',
            component: () => import('@/views/userPage/dynamic'),
            meta: { title: '动态' }
          },
          {
            path: 'follow',
            component: () => import('@/views/userPage/follow'),
            meta: { title: '关注' }
          },
          {
            path: 'fun',
            component: () => import('@/views/userPage/fun'),
            meta: { title: '粉丝' }
          }
        ]
      }
    ]
  },
  {
    path: '/postPage',
    component: layout,
    children: [
      {
        path: '/postPage',
        name: 'PostPage',
        component: () => import('@/views/postPage'),
        meta: { title: 'PostPage' }
      }
    ]
  },
  {
    path: '/personal',
    component: layout,
    children: [
      {
        path: '/personal',
        name: 'Personal',
        redirect: '/personal/home',
        component: () => import('@/views/personal'),
        meta: { title: 'Personal' },
        children: [
          {
            path: 'home',
            component: () => import('@/views/personal/home'),
            meta: { title: '首页' }
          },
          {
            path: 'myInfo',
            component: () => import('@/views/personal/myInfo'),
            meta: { title: '我的信息' }
          },
          {
            path: 'myAvatar',
            component: () => import('@/views/personal/myAvatar'),
            meta: { title: '我的头像' }
          },
          {
            path: 'myCoin',
            component: () => import('@/views/personal/myCoin'),
            meta: { title: '我的硬币' }
          }
        ]
      }
    ]
  },
  {
    path: '/test',
    component: layout,
    children: [
      {
        path: '/test',
        name: 'Test',
        component: () => import('@/views/test/index'),
        meta: { title: 'Test' }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
